package com.shangxia.dog.config.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhouya38158
 * @date 2022/1/21 14:50
 * @apiNote MybatisPlusConfig
 * <p>
 */
@Configuration
@MapperScan("com.shangxia.dog.*.mapper")
public class MybatisPlusConfig {

    @Value("${mybatisplus.dbType}")
    private DbType dbType;

    /**
     * 自动分页
     *
     * @return 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(dbType));
        return interceptor;
    }

    /**
     * @return 主键自增接口实现
     */
//    @Bean
    public IdentifierGenerator identifierGenerator() {
        return obj -> {
            return 0;
        };
    }

}
